﻿

/*
* myTools.h
* 工具函数,宏
* 2012 - 8 - 22 westice
*/

#pragma once              //防止头文件被多次包含

#include <time.h>


//大数
#define LARGENUM(x0,x1) (x0 > x1 ? x0 : x1);

#define SMALLNUM(x0,x1) (x0 < x1 ? x0 : x1);

//行数
#define PRINT_LINE printf("file:%s line:%d\n",__FILE__,__LINE__);

//断言，并有文件名，行数提示
#define MYASSERT(value) if(!(value)){ \
	printf("myAssert Failed : (%s)  in ",#value);\
	PRINT_LINE\
};

//打印，带换行符


//得到当前时间，毫秒级


//计算区段时间
extern int beginTime;
extern int useTime;
extern char* testTimeFlag;
#define TESTTIME_BEGIN(s) beginTime = clock(); \
	printf("%s begin testTime at ",#s);\
	testTimeFlag = #s;\
	PRINT_LINE
	
#define TESTTIME_END useTime = clock() - beginTime;\
	if(beginTime == -1){\
		printf("%s when testTime has not use TESTTIME_BEGIN",testTimeFlag);\
	}else{	\
		printf("%s ",testTimeFlag);\
		printf("use Time:%fs  end at ",useTime/(float)CLOCKS_PER_SEC);\
		PRINT_LINE\
	}\
	beginTime = -1;\
	useTime = -1;\
	testTimeFlag = NULL;
	
	
//随机整数，随即浮点数
extern int hasSetRandSand;
//设置一次种子
#define onceSrand \
if(!hasSetRandSand){\
	srand(time(NULL));\
	hasSetRandSand = 1;\
}

#define myRandFloatOne ((rand()%10000)/10000.0)  // 0~1的随即数
int myRandInt(ix0,ix1) ;
float myRandFloat(fx0,fx1);



//范围结构体
typedef struct myRangeType{
	int pos;
	int length;
}myRange;
myRange createMyRange(int pos,int length);


//打印各种数据结构长度
#define PRINTDATASIZE(x) printf("%s size = %d\n",#x,sizeof(x));
void printDataStructSize();




